package com.taobao.tools;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.User;
import com.taobao.api.request.UserSellerGetRequest;
import com.taobao.api.response.UserSellerGetResponse;
import com.taobao.tools.utils.TaobaoConfig;

public class UserApi {

	public static final String DEFAULT_FIELDS = "user_id,nick,sex,seller_credit,type,has_more_pic,item_img_num,item_img_size,prop_img_num,prop_img_size,auto_repost,promoted_type,status,alipay_bind,consumer_protection,avatar,liangpin,sign_food_seller_promise,has_shop,is_lightning_consignment,has_sub_stock,is_golden_seller,vip_info,magazine_subscribe,vertical_market,online_gaming";

	/**
	 * taobao.user.seller.get 查询卖家用户信息
	 * @param sessionKey
	 * @param fields	需要查询的属性[默认为:]
	 * @return
	 * @throws ApiException
	 */
	public static User getSeller(String sessionKey, String fields) throws ApiException {
		if(fields == null) {
			fields = DEFAULT_FIELDS;
		}
		TaobaoClient client = new DefaultTaobaoClient(TaobaoConfig.getValue(TaobaoConfig.TAOBAO_APIURL), TaobaoConfig.getValue(TaobaoConfig.TAOBAO_APPKEY), TaobaoConfig.getValue(TaobaoConfig.TAOBAO_APPSECRET));
		UserSellerGetRequest req = new UserSellerGetRequest();
		req.setFields(fields);
		UserSellerGetResponse userSellerGetResponse = client.execute(req, sessionKey);
		return userSellerGetResponse.getUser();
	}

	public static void main(String[] args) {
		try {
			String sessionKey = "6101a07451c7f141b993f0a43ea02514b9e857620925477444084963";
			User user = getSeller(sessionKey, null);
			System.out.println("nick:" + user.getNick() + "\tuser_id:" + user.getUserId() + "\t用户是否开过店:" + user.getHasShop());
			System.out.println("用户是否是金牌卖家:" + user.getIsGoldenSeller() + "\t是否是无名良品用户:" + user.getLiangpin() + "\tsex:" + user.getSex());
			System.out.println("图像地址:" + user.getAvatar());
		} catch (ApiException e) {
			e.printStackTrace();
		}
	}
}
